package com.lejin.order.service.impl;

import com.github.wxpay.sdk.WXPay;
import com.lejin.order.entity.OrderInfo;
import com.lejin.order.service.WxpayService;
import com.lejin.order.util.MyWxPayConfig;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class WxpayServiceImpl implements WxpayService {

    @Override
    public String requestPayUrl(String orderId, String context) {

        MyWxPayConfig myWxPayConfig = new MyWxPayConfig();
        WXPay wxPay = new WXPay(myWxPayConfig);
        HashMap<String,String> paramsMap = new HashMap<>();
        paramsMap.put("body",context);
        paramsMap.put("out_trade_no",orderId);
        paramsMap.put("fee_type","CNY");
        paramsMap.put("total_fee","1");
        paramsMap.put("trade_type","NATIVE");
        paramsMap.put("notify_url","http://192.168.54.58:8040/pay/sucess");
        try {
            Map<String, String> responseMap = wxPay.unifiedOrder(paramsMap);
            String payUrl=responseMap.get("code_url");
            return payUrl;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
